GBML manual / Screen

screen_scanlines

Swaps the green of every pair of side-by-side pixels on some rows of the screen and not on others, which gives the whole picture the fine lines of an old television. look is one of the SCANLINES_ constants, strength (1 to 3) is how many rows are swapped, and speed is how fast a moving look travels down the screen. SCANLINES_NONE turns it off.

Works differently on Game Boy - The Game Boy darkens the rows a scanline look names by one shade: a rolling bar is exact, television lines and static become at most 5 stripes of 3 rows that start a little way along their row; sprites keep their shades. It does not run with a backdrop look.

Game Boy Color: not available

Sega Genesis: not built yet

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

screen_scanlines(look, strength, speed)

Arguments

NameType
lookscanline_look
strengthint
speedreal

Returns

Nothing.

Description

Swaps the green of every pair of pixels that sit side by side - the first with the second, the third with the fourth, all along the row - on some rows of the screen and not on others. It is the same trick green_swap plays on the whole picture, row by row. The picture gets the fine lines of an old television set, or a bar of interference that rolls down the screen, or noise.

A real capture, five pictures of a striped lighthouse standing in front of a wall of thin blue stripes and a floor of thin gold stripes - first as it is, then with green_swap(true) on its own (every row turns pink and green), then with each of the three SCANLINES_ looks in turn at strength 2 (every other row turns pink and green, a bar of rows across the top of the screen, and rows picked at random)A real capture, five pictures of a striped lighthouse standing in front of a wall of thin blue stripes and a floor of thin gold stripes - first as it is, then with green_swap(true) on its own (every row turns pink and green), then with each of the three SCANLINES_ looks in turn at strength 2 (every other row turns pink and green, a bar of rows across the top of the screen, and rows picked at random)
A real capture, five pictures of a striped lighthouse standing in front of a wall of thin blue stripes and a floor of thin gold stripes - first as it is, then with greenswap(true) on its own (every row turns pink and green), then with each of the three SCANLINES looks in turn at strength 2 (every other row turns pink and green, a bar of rows across the top of the screen, and rows picked at random)

A lighthouse in front of a wall and a floor of one-pixel stripes, as it is, then with the plain green_swap(true), then each look at strength 2, standing still. The stripes are there on purpose: swapping the green shows only where two pixels side by side have different greens, and these do. A row that is swapped turns pink and green. Real pictures from a Game Boy Advance ROM.

You give it three things:

Which look

LookWhat it isWhat strength 1, 2 and 3 are
SCANLINES_CRTfine lines, like an old televisionone row in four, every other row, three rows in four
SCANLINES_ROLLone bar of swapped rows that rolls down the screena bar 16, 32 and 64 rows tall
SCANLINES_STATICrows picked at random, the same every time you run the gameabout one row in four, one in two, three in four

What it changes

It changes the whole picture: sprites, backgrounds and text alike. Nothing needs to be marked first.

Swapping the green only shows where two pixels side by side have different amounts of green. In a flat area the two greens are the same, so the swap changes nothing you can see. Pictures with lots of detail show it best.

It and green_swap

green_swap turns the swap on or off for every row at once. A scanline look decides row by row. When both are in play the look wins:

One at a time

The console has just one green-swap switch, so there is at most one scanline look at a time. Asking for a different look, or the same look at a different strength, replaces the first one and keeps the pattern where it was. Asking again for the same look and strength only changes the speed.

Call it once

You do not need to call it every frame. Call it once - when the room starts is a good time - and the look keeps going by itself. A look belongs to the screen, so there is nothing to remember and nothing to lose: the look ends by itself when a room is loaded (you change room, or restart the one you are in), so a new room that wants a pattern asks for its own.

Turning it off

screen_scanlines(SCANLINES_NONE, 0, 0);

This gives its slot back straight away. The last two numbers are ignored, but they have to be there.

Always destroy it, do not hide it. There is no way to hide a look, on purpose: something hidden would look gone but would still be using up one of the console's few row-by-row slots, and then the next effect you ask for would not appear and nothing would tell you why. Off always means the slot is free.

What it costs

A scanline look uses one of the 8 row-by-row effects the console has, and no matrix, no sprite and no memory worth counting. A room change keeps two of the eight for itself, so there are six left for you, shared with everything else that works row by row: screen_backdrop, draw_sprite_ripple, sprite_warp and the others. You can see how many are in use on the debug screen: the line called H-BLANK.

The patterns live in the cartridge: 160 to 320 bytes each, and a call that names its look keeps only that one. Measured on a real ROM, a look that stands still costs about 1 hundredth of a frame, and one that moves costs about 1.5 hundredths.

When there is no room

Ask for more than there is and the game does not skip it. A development build stops with a message that says how many slots there are and names every look that is holding one, so you know which one to turn off. A release build, which has no way to stop and show a message, draws the screen with no look. It never half-works.

Example

screen_scanlines(SCANLINES_CRT, 2, 0);

The fine lines of an old television, on every picture in the game. Call it in the Create event.

if (btn_pressed(BTN_A)) {
    screen_scanlines(SCANLINES_ROLL, 2, 0.5);
}

Pressing A sends a bar of interference rolling down the screen. Pressing A again while the bar is already rolling changes nothing, because it is the same look and strength.

On the GBA

Costs ONE of the console’s 8 row-by-row (H-Blank) effects for as long as the look is on, and no matrix, no sprite and no memory worth counting. A room change keeps two of the eight for itself, so six are left for you, shared with everything else that works row by row. It changes the WHOLE picture - sprites, backgrounds and text alike - and needs nothing marked. The console has just ONE green-swap switch, so there is at most one scanline look at a time: asking for a different look or strength replaces the first, and asking again for the same look and strength only changes the speed. green_swap(true) swaps every row, and it is not lost while a look runs: the look decides every row, the first row included, and the plain switch is remembered and takes over again when you turn the look off. A pattern that moves moves four rows at a time, because that is how the console reads it. The tables are in the cartridge (160 to 320 bytes each; a call with a look written out keeps only that one). A look stays until you turn it off or a room is loaded (a restart counts). Turning it off with SCANLINES_NONE hands the slot back at once, but hiding something does not: destroy it, do not hide it. If there is no room for another one, a development build stops with a message that names every look holding a slot; a release build draws the screen with no look. The in-game debug overlay shows the count as H-BLANK.

See also: green_swapscreen_blendscreen_mosaicscreen_backdropdraw_sprite_ripple